%% 5.3	Water balance
close all; clearvars; clc;

%% 5.3.a.I
% In a profile, soil moisture is measured twice; at t=t0 and t=t1.

z           = [00 10 20 40 60 80];      % [cm]
theta_t0    = [20 20 25 30 40 50]./100; % [-]
theta_t1    = [50 40 35 30 40 50]./100; % [-]

p           = theta_t0(z==80);

% The groundwater level is at 80 cm below surface. Draw the two soil 
% moisture profiles in one graph.

figure(1);
plot(theta_t0,-z);
xlabel('Relative soilmoisture theta [-]');
ylabel('depth [cm]');
figure(2);
plot(theta_t1,-z);
xlabel('Relative soilmoisture theta [-]');
ylabel('depth [cm]');

%% 5.3.a.II
% Calculate how much water is added.

% Integrate the soilmoisture over the depth. The difference between t0 and
% t1 is the added water.

% Numerical integration using trapezium method
Q_t0    = trapz(z,theta_t0);    % [cm] of water column at t0
Q_t1    = trapz(z,theta_t1);    % [cm] of water column at t1

fprintf('The added water is %f [cm]\n', Q_t1-Q_t0);

%% 5.3.b.I
% At t=t2 the soil moisture profile is measured again.
% Draw also this soil moisture profile.
theta_t2    = [25 35 40 35 40 50]./100;     % [cm]

figure(3);
plot(theta_t2,-z);
xlabel('Relative soilmoisture theta [-]');
ylabel('depth [cm]');

%% 5.3.b.II
% How much water is evaporated? 
Q_t2    = trapz(z,theta_t2);    % [cm] of water column at t2

fprintf(['In the first timestep water is being infiltrated. In the next'... 
    'step, t=2 %f [cm] of water is added\n'],Q_t2-Q_t1);

fprintf(['Apparently the quantity of water in the unsaturated soil remains'... 
    'the same, all the water infiltrates/percolates/results in seepage\n']);

fprintf(['This is not possible, is the time differences between the time'...
    'steps are not given. if assumed the time differences between the '...
    'timesteps is 1 day. The entire difference of %f [cm] infilterates in 1 day'...
    'thus the infiltration velocity is %f [cm/day]\n']);

% If the time step is 1 day, what is the average percolation velocity of the soil moisture front?
